home *** CD-ROM | disk | FTP | other *** search
/ BUG 1 / BUGCD1996_0708.ISO / pc / util / minilin / minilin.exe / SBIN / NETCONFI.{1Q < prev    next >
Text File  |  1994-06-09  |  13KB  |  471 lines

  1. #!/bin/sh 
  2. # This checks IP address syntax.
  3. # usage: syntax_check ADDRESS #-OF-EXPECTED-SEGMENTS (up to 4)
  4. # example: syntax_check 123.22.43.1 4
  5. # returns: 0=found correct  1=too many fields  2=non numeric field found
  6. syntax_check() {
  7.   RET_CODE=0 
  8.   SCRATCH=$1
  9.   SCRATCH=`echo $SCRATCH | tr "." "/"`
  10.   INDEX=$2
  11.   while [ ! "$INDEX" = "0" ]; do
  12.     # OK, so I'm a LISP-head :^)
  13.     FIELD=`basename $SCRATCH`
  14.     SCRATCH=`dirname $SCRATCH`
  15.     if expr $FIELD + 1 1> /dev/null 2> /dev/null; then
  16.       GOOD=y
  17.     else
  18.       RET_CODE=2; # non-numeric field
  19.     fi
  20.     INDEX=`expr $INDEX - 1`
  21.   done
  22.   if [ ! "$SCRATCH" = "." ]; then
  23.     RET_CODE=1; # too many arguments
  24.   fi
  25.   if [ "$3" = "WARN" -a ! "$RET_CODE" = "0" ]; then
  26.     cat << EOF
  27.  
  28. The address you have entered seems to be non-standard. We were expecting $2
  29. groups of numbers seperated by dots, like: 127.0.0.1
  30. Are you absolutely sure you want to use the address $1?
  31.  
  32. EOF
  33.     echo -n "Use funny address $1 ([y]es, [n]o)? "
  34.     read USE_FUNNY;
  35.     echo
  36.     if [ "$USE_FUNNY" = "y" ]; then
  37.       RET_CODE = 0;
  38.     fi
  39.   else
  40.     if [ "$3" = "ECHO" ]; then
  41.       echo $RET_CODE;
  42.     fi
  43.   fi
  44.   return $RET_CODE;
  45. }
  46.  
  47. if [ ! -r vmlinuz -a ! -r zImage ]; then # cheap, but it works :^)
  48.  cd /
  49. fi;
  50.  
  51. ############################################################################
  52. #
  53. #  Disclaimer:
  54. #
  55. #  WARNING! USE THIS SCRIPT AT YOUR OWN RISK, I HAVE NO IDEA WHAT IT
  56. #  WILL DO IF RUN ON YOUR COMPUTER! I ACCEPT NO RESPONSIBILITY!
  57. #
  58. #  A script to help get you on the net. Original idea from the MCC
  59. #  install.net.  This script asks you for your hostname, domainname, IP
  60. #  address, network address, gateway, netmask, broadcast address, and
  61. #  your DNS server.  It then proceeds to set up the networking files
  62. #  using the answers you gave it.  Make sure that the files and programs 
  63. #  point to the right directory.  This is set up as documented in the 
  64. #  NET-2-HOWTO. Please email me about any problems with, or errors in, 
  65. #  the script.
  66. #
  67. #                            Jim Robinson
  68. #                            jimr@simons-rock.edu
  69. ############################################################################
  70. #
  71. # IMPORTANT!!! NO LEADING '/' in the paths below, or this script will not
  72. # function from the bootdisk.
  73. IFCONFIG=sbin/ifconfig            # Where ifconfig program is.
  74. ROUTE=sbin/route            # Where route program is.
  75. RC=etc/rc.d/rc.inet1            # Where rc.inet1 file is.
  76. RESOLV=etc/resolv.conf            # Where resolv.conf file is.
  77. HOSTS=etc/hosts                 # Where hosts file is.
  78. ETCNETWORKS=etc/networks        # Where networks file is.
  79. SMAIL=var/lib/smail/config        # Smail configuration file
  80. ELMRC=var/lib/elm/elm.rc        # ELM rc file
  81. #
  82. # defaults:
  83. NETWORK=127.0.0.0
  84. IPADDR=127.0.0.1
  85. #
  86. ############################################################################
  87. #             Question and answer.
  88. ############################################################################
  89. #
  90. cat << EOF
  91.  
  92. NETWORK CONFIGURATION
  93.  
  94. Now we will attempt to configure your mail and TCP/IP. This process probably
  95. won't work on all possible network configurations, but should give you a good
  96. start. You will be able to reconfigure your system at any time by typing:
  97.   
  98.   netconfig
  99.  
  100. EOF
  101. HOSTNAME=""
  102. while [ "$HOSTNAME" = "" ]; do
  103. cat << EOF
  104. First, we'll need the name you'd like to give your host. Only the base
  105. hostname is needed right now. (not the domain)
  106.  
  107. EOF
  108.  echo -n "Enter hostname: "
  109.  read HOSTNAME
  110. done
  111.  
  112. while [ "$DOMAIN" = "" ]; do
  113. cat << EOF
  114.  
  115. Now, we need the domain name. Do not supply a leading '.'
  116.  
  117. EOF
  118.  echo -n "Enter domain name for $HOSTNAME: "
  119.  read DOMAIN
  120. done
  121. echo
  122.  
  123. cat << EOF
  124. If you only plan to use TCP/IP through loopback, then your IP address will
  125. be 127.0.0.1 and we can skip a lot of the following questions.
  126.  
  127. EOF
  128.  
  129. LOOPBACK=unknown
  130. while [ ! "$LOOPBACK" = "y" -a ! "$LOOPBACK" = "n" ]; do
  131.  echo -n "Do you plan to ONLY use loopback ([y]es, [n]o)? "
  132.  read LOOPBACK;
  133.  echo
  134. done
  135.  
  136. if [ -r etc/rc.d/rc.inet1 -a "$LOOPBACK" = "n" ]; then
  137.  
  138.  while [ 0 ]; do
  139.   echo "Enter your IP address for the local machine. Example: 111.112.113.114"
  140.   echo -n "Enter IP address for $HOSTNAME (aaa.bbb.ccc.ddd): "
  141.   read IPADDR
  142.   if [ "$IPADDR" = "" ]; then
  143.     continue;
  144.   fi
  145.   syntax_check $IPADDR 4 WARN
  146.   if [ $? = 0 ]; then
  147.     break;
  148.   fi
  149.  done
  150.  echo
  151.  
  152.  while [ 0 ]; do
  153.   echo "Enter your network address. This will usually be your IP address"
  154.   echo "with the last number replaced by 0, such as 111.112.113.0"
  155.   echo -n "Enter network address (aaa.bbb.ccc.ddd): "
  156.   read NETWORK
  157.   if [ "$NETWORK" = "" ]; then
  158.     continue;
  159.   fi
  160.   syntax_check $NETWORK 4 WARN
  161.   if [ $? = 0 ]; then
  162.     break;
  163.   fi
  164.  done
  165.  echo
  166.  
  167.  while [ 0 ]; do
  168.   echo "Enter your gateway address, such as 111.112.113.1"
  169.   echo -n "Enter gateway address (aaa.bbb.ccc.ddd): "
  170.   read GATEWAY
  171.   if [ "$GATEWAY" = "" ]; then
  172.     continue;
  173.   fi
  174.   syntax_check $GATEWAY 4 WARN
  175.   if [ $? = 0 ]; then
  176.     break;
  177.   fi
  178.  done
  179.  echo
  180.  
  181.  while [ 0 ]; do
  182.   echo "Enter your netmask. This will generally look something"
  183.   echo "like this: 255.255.255.0"
  184.   echo -n "Enter netmask (aaa.bbb.ccc.ddd): "
  185.   read NETMASK
  186.   if [ "$NETMASK" = "" ]; then
  187.     continue;
  188.   fi
  189.   syntax_check $NETMASK 4 WARN
  190.   if [ $? = 0 ]; then
  191.     break;
  192.   fi
  193.  done
  194.  echo
  195.  
  196.  while [ "$BROADCAST" = "" ]; do
  197.   echo "Your broadcast address will usually be your IP address"
  198.   echo "with 255 replacing the last value, such as: 111.112.113.255"
  199.   echo -n "Enter broadcast address (aaa.bbb.ccc.ddd): "
  200.   read BROADCAST
  201.   if [ "$BROADCAST" = "" ]; then
  202.     continue;
  203.   fi
  204.   syntax_check $BROADCAST 4 WARN
  205.   if [ $? = 0 ]; then
  206.     break;
  207.   fi
  208.  done
  209.  echo
  210.  
  211.  echo "Setting up TCP/IP..."
  212. else
  213.  if [ ! -r etc/rc.d/rc.inet1 ]; then
  214.  cat << EOF
  215.  
  216. You do not seem to have TCP/IP installed, so all I can really set up for
  217. you is your hostname/domainname. This won't mean much since you're not on
  218. the network, but it will let you have the hostname you prefer shown at the
  219. login prompt.
  220.  
  221. EOF
  222.  fi
  223. fi
  224.  
  225. echo "Creating /etc/HOSTNAME..."
  226. echo $HOSTNAME.$DOMAIN > etc/HOSTNAME
  227.  
  228. #
  229. ############################################################################
  230. #              The rc.inet1 file.
  231. ############################################################################
  232. #
  233. if [ -f $RC ]; then 
  234.  cp $RC tmp/`basename $RC`.OLD
  235.  echo "Creating /$RC..."
  236. if [ "$LOOPBACK" = "n" ]; then # we are using an ethernet card
  237.  /bin/cat <<EOF >$RC
  238. #! /bin/sh
  239. #
  240. # rc.inet1    This shell script boots up the base INET system.
  241. #
  242. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  243. #
  244.  
  245. HOSTNAME=\`cat /etc/HOSTNAME\`
  246.  
  247. # Attach the loopback device.
  248. /$IFCONFIG lo 127.0.0.1
  249. /$ROUTE add -net 127.0.0.0
  250.  
  251. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  252. # eth0 interface. If you're only using loopback or SLIP, don't include the
  253. # rest of the lines in this file.
  254.  
  255. # Edit for your setup.
  256. IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  257. NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  258. NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  259. BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  260.             # have one. If not, leave blank and edit below.
  261. GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  262.  
  263. # Uncomment ONLY ONE of the three lines below. If one doesn't work, try again.
  264. # /$IFCONFIG eth0 \${IPADDR} netmask \${NETMASK} broadcast \${BROADCAST}
  265. /$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  266. # /$IFCONFIG  eth0 \${IPADDR} netmask \${NETMASK} 
  267.  
  268. # Uncomment these to set up your IP routing table.
  269. /$ROUTE add -net \${NETWORK} netmask \${NETMASK}
  270. /$ROUTE add default gw \${GATEWAY} metric 1
  271.  
  272. # End of rc.inet1
  273. EOF
  274.   chmod 755 $RC
  275.  else # we are only using loopback
  276.   /bin/cat <<EOF >$RC
  277. #! /bin/sh
  278. #
  279. # rc.inet1    This shell script boots up the base INET system.
  280. #
  281. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  282. #
  283.  
  284. HOSTNAME=\`cat /etc/HOSTNAME\`
  285.  
  286. # Attach the loopback device.
  287. /$IFCONFIG lo 127.0.0.1
  288. /$ROUTE add -net 127.0.0.0
  289.  
  290. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  291. # eth0 interface. If you're only using loopback or SLIP, don't include the
  292. # rest of the lines in this file.
  293.  
  294. # Edit for your setup.
  295. #IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  296. #NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  297. #NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  298. #BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  299.             # have one. If not, leave blank and edit below.
  300. #GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  301.  
  302. # Uncomment ONLY ONE of the three lines below. If one doesn't work, try again.
  303. # /$IFCONFIG eth0 \${IPADDR} netmask \${NETMASK} broadcast \${BROADCAST}
  304. #/$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  305. # /$IFCONFIG  eth0 \${IPADDR} netmask \${NETMASK} 
  306.  
  307. # Uncomment these to set up your IP routing table.
  308. #/$ROUTE -n add \${NETWORK} netmask \${NETMASK}
  309. #/$ROUTE add default gw \${GATEWAY} metric 1
  310.  
  311. # End of rc.inet1
  312. EOF
  313.   chmod 755 $RC
  314.  fi # write out the script
  315. fi # only alter if it already exists
  316. #
  317. ############################################################################
  318. #              The networks file.
  319. ############################################################################
  320. #
  321. if [ -f $ETCNETWORKS ]; then cp $ETCNETWORKS tmp/`basename $ETCNETWORKS`.OLD;fi
  322. echo "Creating /$ETCNETWORKS..."
  323. /bin/cat <<EOF >$ETCNETWORKS
  324. #
  325. # networks    This file describes a number of netname-to-address
  326. #        mappings for the TCP/IP subsystem.  It is mostly
  327. #        used at boot time, when no name servers are running.
  328. #
  329. # Version:    @(#)/etc/networks    2.00    04/30/93
  330. #
  331. # Author:    Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org
  332. #
  333.  
  334. loopback    127.0.0.0
  335. localnet    $NETWORK
  336.  
  337. # End of networks.
  338. EOF
  339. chmod 644 $ETCNETWORKS
  340. #
  341. ############################################################################
  342. #               The hosts file.
  343. ############################################################################
  344. #
  345. echo "Creating /$HOSTS..."
  346. if [ -f $HOSTS ];then cp $HOSTS tmp/`basename $HOSTS`.OLD;fi
  347. /bin/cat <<EOF >$HOSTS
  348. #
  349. # hosts        This file describes a number of hostname-to-address
  350. #        mappings for the TCP/IP subsystem.  It is mostly
  351. #        used at boot time, when no name servers are running.
  352. #        On small systems, this file can be used instead of a
  353. #        "named" name server.  Just add the names, addresses
  354. #        and any aliases to this file...
  355. #
  356. # Version:    @(#)/etc/hosts        2.00    04/30/93
  357. #
  358. # Author:    Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  359. #
  360.  
  361. # For loopbacking.
  362. 127.0.0.1    localhost
  363. $IPADDR     $HOSTNAME.$DOMAIN $HOSTNAME
  364.  
  365. # End of hosts.
  366. EOF
  367. chmod 644 $HOSTS
  368. #
  369. ##########################################################################
  370. # The Smail 3.1.28 configuration file 
  371. ##########################################################################
  372. #
  373. mkdir -p `dirname $SMAIL`
  374. if [ -f $SMAIL ];then 
  375.  cp $SMAIL tmp/`basename $SMAIL`.OLD
  376. fi
  377. echo "Creating /$SMAIL..."
  378. /bin/cat <<EOF >$SMAIL
  379. #
  380. #    smail configuration for $HOSTNAME
  381. # (see smail(5) man page for details and other options)
  382. #
  383. -smtp_debug
  384. hostname=$HOSTNAME.$DOMAIN
  385. visible_domain=$DOMAIN
  386. more_hostnames=$HOSTNAME.$DOMAIN
  387. postmaster=postmaster
  388. smtp_accept_max=10
  389. EOF
  390. echo 'smtp_banner="$primary_name Linux Smail$version #$compile_num ready at $date"' >> $SMAIL
  391. echo 'received_field="Received: \ ' >> $SMAIL
  392. echo '    ${if def:sender_host \ ' >> $SMAIL
  393. echo '        {from $sender_host by $primary_name \ ' >> $SMAIL
  394. echo '        ${if def:sender_proto: with $sender_proto}\ ' >> $SMAIL
  395. echo '        \n\t(Linux Smail$version #$compile_num) }\ ' >> $SMAIL
  396. echo '    else{by $primary_name ${if def:sender_proto:with $sender_proto }\ ' >> $SMAIL
  397. echo '        (Linux Smail$version #$compile_num)\n\t}}\ ' >> $SMAIL
  398. echo '    id $message_id; $spool_date" ' >> $SMAIL
  399. chmod 644 $SMAIL
  400. #
  401. ############################################################################
  402. # The ELM rc file
  403. ############################################################################
  404. #
  405. mkdir -p `dirname $ELMRC`
  406. if [ -f $ELMRC ];then
  407.  cp $ELMRC tmp/`basename $ELMRC`.OLD
  408. fi
  409. echo "Creating /$ELMRC..."
  410. /bin/cat <<EOF >$ELMRC
  411. #------------------------ global elm.rc file ------------------
  412. #
  413. # this expects any global aliases in /usr/lib/aliases.text
  414. #
  415. # you probably also want to set the visible_name parameter in 
  416. # /usr/lib/smail/config if you use smail3.1.28
  417. #
  418. # this is the unqualified hostname
  419. #
  420. hostname = $HOSTNAME
  421. #
  422. # this is the local domain
  423. #
  424. hostdomain = .$DOMAIN
  425. #
  426. # this is the fully qualified hostname
  427. #
  428. hostfullname = $HOSTNAME.$DOMAIN
  429. EOF
  430. chmod 644 $ELMRC
  431. #
  432. ############################################################################
  433. #            The resolv.conf file.
  434. ############################################################################
  435. #
  436. if [ "$LOOPBACK" = "n" ]; then
  437.  cat << EOF
  438. Here is your current IP address, full hostname, and base hostname:
  439. $IPADDR       $HOSTNAME.$DOMAIN    $HOSTNAME
  440.  
  441. Please give the IP address of the name server to use. 
  442. You can add more Domain Name Servers by editing /$RESOLV.
  443.  
  444. EOF
  445.  while [ "$NAMESERVER" = "" ]; do
  446.   echo -n "Name Server for domain $DOMAIN (aaa.bbb.ccc.ddd): "
  447.   read NAMESERVER
  448.  done
  449.  
  450.  if [ -f $RESOLV ]; then cp $RESOLV tmp/`basename $RESOLV`.OLD;fi
  451.  echo "domain $DOMAIN" >$RESOLV
  452.  echo "nameserver $NAMESERVER" >>$RESOLV
  453. else
  454.  echo "domain $DOMAIN" >$RESOLV
  455. fi
  456. if [ "$LOOPBACK" = "n" ]; then chmod 644 $RESOLV ;fi
  457. #
  458. ############################################################################
  459. #             Change permissions and exit.
  460. ############################################################################
  461. #
  462. chown root.root $HOSTS $RESOLV $RC
  463. chmod 644 $HOSTS $RESOLV
  464. chmod 754 $RC
  465.  
  466. cat << EOF
  467.  
  468. Your networking software has now been configured. 
  469.  
  470. EOF
  471.